<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>jQuery-jsonp</title>
    <style>
      #result {
        width: 300px;
        height: 100px;
        border: 3px solid pink;
      }
    </style>
    <script
      crossorigin="anonymous"
      src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js"
    ></script>
  </head>
  <body>
    <button>点击发送 jsonp 请求</button>
    <!-- 点击按钮返回数据到result元素中 -->
    <div id="result"></div>
    <script>
      $("button").click(function () {
        // url?callback=? 固定格式
        $.getJSON(
          "http://127.0.0.1:8000/jquery-jsonp?callback=?",
          function (data) {
            console.log(data);
            $("#result").html(`
            名称: ${data.name}
            </br>
            年龄: ${data.age}
          `);
          }
        );
      });
    </script>
  </body>
</html>
